/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBeans;

import controladores.FacturarCont;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import modelos.pojos.CheckInHabitacion;
import org.apache.log4j.Logger;
import org.primefaces.component.datatable.DataTable;
import org.primefaces.component.inputtext.InputText;

/**
 *
 * @author ricardo
 */
@ManagedBean
@ViewScoped
public class FacturaHabitacion implements Serializable {

    private modelos.pojos.CheckInHabitacion checkInHabitacion;
    private double valor;
    private int duracionDias;
    private String codigoReservaPadre;
    private DataTable tablaCheckIns;
    protected Logger log = Logger.getLogger(FacturaHabitacion.class);
    
    /** Creates a new instance of FacturaHabitacion */
    public FacturaHabitacion() {
        checkInHabitacion = new CheckInHabitacion();
    }

    public DataTable getTablaCheckIns() {
        return tablaCheckIns;
    }

    public void setTablaCheckIns(DataTable tablaCheckIns) {
        this.tablaCheckIns = tablaCheckIns;
    }

    public CheckInHabitacion getCheckInHabitacion() {
        return checkInHabitacion;
    }

    public void setCheckInHabitacion(CheckInHabitacion checkInHabitacion) {
        this.checkInHabitacion = checkInHabitacion;
    }

    public double getValor() {
        return valor;
    }

    public void setValor(double valor) {
        this.valor = valor;
    }

    public int getDuracionDias() {
        return duracionDias;
    }

    public void setDuracionDias(int duracionDias) {
        this.duracionDias = duracionDias;
    }
    
    public void consultarCheckIn(){
        checkInHabitacion = (CheckInHabitacion) tablaCheckIns.getRowData();
        duracionDias = FacturarCont.determinarDuracionReserva(checkInHabitacion.getFechaIn());
    }
    
    public List<modelos.pojos.CheckInHabitacion> listarCheckInHabitacion(){
        FacesContext facesContext = FacesContext.getCurrentInstance();
        UIViewRoot root = facesContext.getViewRoot();
        InputText caja = (InputText) root.findComponent("furm").findComponent("codReserva");
        codigoReservaPadre = caja.getValue()+"";
        return FacturarCont.listarCheckInHabitacionFacturables(codigoReservaPadre);
    }
    
    public void facturar(){
        log.info("entre");
        FacturarCont.cerrarFacturaReservaHabitacion(codigoReservaPadre, checkInHabitacion.getReservaHabitacion().getHabitacion().getNumero(), valor);
        log.info("factura");
    }    
}
